package com.hdu.careerplan.pojo.pythonData;

import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.util.Map;

@Document("salaryRes")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SalaryData {

    @Field("region")
    private String region; // 地区/国家
    @Field("jobName")
    private String jobName; // 岗位名
    @Field("jobNum")
    private Integer jobNum; // 岗位数量
    @Field("avgSalary")
    private Double avgSalary; // 平均年薪
    @Field("maxSalary")
    private Double maxSalary; // 平均最高年薪
    @Field("minSalary")
    private Double minSalary; // 平均最低年薪

    private String unit = "K"; // 单位


    /**
     * python 年薪相关数据分析
     * @param region 地区
     * @param jobName 岗位
     * @param jsonData 所分割好的字符串
     */
    public SalaryData(String region, String jobName, String jsonData) {
//        System.out.println(jsonData);
        Map<String, String> map = JSON.parseObject(jsonData, Map.class);
        this.region = region;
        this.jobName = jobName;
        this.avgSalary = Double.parseDouble(String.valueOf(map.get("平均年薪")));
        this.maxSalary = Double.parseDouble(String.valueOf(map.get("平均最高年薪")));
        this.minSalary = Double.parseDouble(String.valueOf(map.get("平均最低年薪")));
        this.jobNum = Integer.parseInt(String.valueOf(map.get("岗位数量")));
        this.unit = "K";

    }

    /**
     * python 年薪相关数据分析
     * @param flag 0，一个城市多个岗位；1，一个岗位多个城市
     * @param comparedContent 0，值为城市；1，值为岗位
     * @param jsonData 所分割好的字符串
     */
    public SalaryData(int flag, String comparedContent, String jsonData ){
        if (flag == 0) { // 为0的时候一个城市多个岗位，城市不包含在python的数据当中
            this.region = comparedContent;
            this.unit = "K";
            Map<String, String> map = JSON.parseObject(jsonData, Map.class);
            this.jobName = map.get("职位类型");
            this.avgSalary = Double.parseDouble(map.get("平均年薪"));
            this.maxSalary = Double.parseDouble(map.get("平均最高年薪"));
            this.minSalary = Double.parseDouble(map.get("平均最低年薪"));
            this.jobNum = Integer.parseInt(map.get("岗位数量"));

        }
        else if (flag == 1) { // 为1的时候一个岗位多个城市，岗位不包含在python的数据当中
            this.jobName = comparedContent;
            this.unit = "K";
            Map<String, String> map = JSON.parseObject(jsonData, Map.class);
            this.region = map.get("城市");
            this.avgSalary = Double.parseDouble(map.get("平均年薪"));
            this.maxSalary = Double.parseDouble(map.get("平均最高年薪"));
            this.minSalary = Double.parseDouble(map.get("平均最低年薪"));
            this.jobNum = Integer.parseInt(map.get("岗位数量"));

        }
        else System.out.println("data is wrong");
    }




}
